/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-09 16:36:01
 * @FilePath: /yt-devops/lib/pages/tabs/device_tab/device_tab_model.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'dart:ffi';

import 'package:flutter/widgets.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/model/device_model.dart';
import 'package:yt_devops/pages/devices/device_list/device_list_model.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/air_condition_detail/air_condition_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/battery_pack_detail/battery_pack_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/business_electricity_storage_device_detail/business_electricity_storage_device_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/charging_station/charging_station_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/electric_meter/electric_meter_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/electricity_meter_detail/electricity_meter_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/ems_detail/ems_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/self_develop_ems_detail/self_develop_ems_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/fire_fighting/air_cool_fire_detail/air_cool_fire_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/new_air_cooling_page/new_air_cooling_page_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/pcs_detail/pcs_detail_view.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/pv_inverter_detail/pv_inverter_detail_view.dart';
import 'package:yt_devops/utils/enums.dart';

class DeviceTabModel {
  Map<ProductType, Widget Function(DeviceModel?, int)> deviceProductTypeMap = {
    ProductType.pvIntervert: (DeviceModel? deviceModel, int deviceId) =>
        PvInverterDetailPage(),
    ProductType.electricyMeter: (DeviceModel? deviceModel, int deviceId) =>
        ElectricityMeterDetailPage(),
    ProductType.energyElectricMeter: (DeviceModel? deviceModel, int deviceId) =>
        ElectricMeterPage(
          deviceId: deviceId,
          deviceModel: deviceModel,
        ),
    ProductType.smallESS: (DeviceModel? deviceModel, int deviceId) =>
        BusinessElectricityStorageDeviceDetailPage(deviceModel),
    ProductType.windSolarDieselESS: (DeviceModel? deviceModel, int deviceId) =>
        BusinessElectricityStorageDeviceDetailPage(deviceModel),
    ProductType.solarESS: (DeviceModel? deviceModel, int deviceId) =>
        BusinessElectricityStorageDeviceDetailPage(deviceModel),
    ProductType.bussinessEnergyStorage:
        (DeviceModel? deviceModel, int deviceId) =>
            BusinessElectricityStorageDeviceDetailPage(deviceModel),
    ProductType.batteryPack: (DeviceModel? deviceModel, int deviceId) =>
        const BatteryPackDetailPage(),
  };

  Map<ProductIDType, Widget Function(DeviceModel?, DeviceListModel?)>
      deviceProductIDMap = {
    ProductIDType.pcs:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            PcsDetailPage(deviceModel: deviceModel),
    ProductIDType.aircondition:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            AirConditionDetailPage(deviceModel: deviceModel),
    ProductIDType.p100CAir:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            AirConditionDetailPage(deviceModel: deviceModel),
    ProductIDType.ems:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            EmsDetailPage(deviceModel: deviceModel),
    ProductIDType.bWattEms:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            EmsDetailPage(deviceModel: deviceModel),
    ProductIDType.bWattPcs:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            PcsDetailPage(deviceModel: deviceModel),
    ProductIDType.yTEnergyEms:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            SelfDevelopEmsDetailPage(deviceModel: deviceModel),
    ProductIDType.yTEnergyPcs:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            PcsDetailPage(deviceModel: deviceModel),
    ProductIDType.energyFireFight:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            const FireFightingDetailPage(),
    ProductIDType.YTYCharge801:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge802:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge1801:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge1802:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge3201:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge3202:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge4001:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge4002:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge1601:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge1602:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge2401:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTYCharge2402:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY60GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY60GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY80GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY80GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY120GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY120GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY160GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY160GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY180GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY180GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY240GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY240GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY320GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY320GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY400GBAG1_1:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY400GBAG1_2:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.YTY60GBAG12:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.chargeS2801:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.chargeEU4801:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.chargeS2401:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.chargeY3001:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.chargeY3002:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            ChargingStationView(deviceInfo: deviceModel),
    ProductIDType.FGCCEnergyBatteryStack:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            NewAirCoolingPage(
              deviceModel: deviceModel,
              deviceTree: deviceTree,
            ),
    ProductIDType.react100WEmsEnergy:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            EmsDetailPage(deviceModel: deviceModel),
    ProductIDType.react100XEmsEnergy:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            EmsDetailPage(deviceModel: deviceModel),
    ProductIDType.react100WMeter:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            NewAirCoolingPage(
              deviceModel: deviceModel,
              deviceTree: deviceTree,
            ),
    ProductIDType.yTEnergyAir:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            AirConditionDetailPage(
              deviceModel: deviceModel,
            ),
    ProductIDType.bWattAir:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            AirConditionDetailPage(
              deviceModel: deviceModel,
            ),
    ProductIDType.hwPvIntervert:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            NewAirCoolingPage(
              isNew: false,
              deviceModel: deviceModel,
              subDevicesIdList: const [],
              subDevicesNameList: const [],
              deviceTree: deviceTree,
            ),
    ProductIDType.kTL3PV:
        (DeviceModel? deviceModel, DeviceListModel? deviceTree) =>
            NewAirCoolingPage(
              isNew: false,
              deviceModel: deviceModel,
              subDevicesIdList: const [],
              subDevicesNameList: const [],
              deviceTree: deviceTree,
            )
  };

  Widget getDeviceDetailPage(
      {required DeviceModel? deviceModel,
      required int deviceId,
      required ProductIDType? productIdType,
      required ProductType? productType,
      required List<int> subDevicesIdList, //设备详情ems需要订阅的子设备
      required List<String> subDevicesNameList, //设备详情ems需要订阅的子设备名称,
      DeviceListModel? deviceTree}) {
    Log.d('deviceId===' + deviceId.toString());
    Log.d('productId===' + productIdType.toString());
    Log.d('subDevicesNameList===' + subDevicesNameList.toString());

    return deviceProductIDMap[productIdType]?.call(
          deviceModel,
          deviceTree,
        ) ??
        deviceProductTypeMap[productType]?.call(deviceModel, deviceId) ??
        NewAirCoolingPage(
          isNew: !([
            ProductIDType.liquidEnergyEms,
            ProductIDType.liquidEnergyPcs,
            ProductIDType.liquidEnergyAir,
            ProductIDType.liquidEnergyDehumidifier,
            ProductIDType.liquidEnergyFireFight
          ].contains(productIdType)), //旧的液冷,
          deviceModel: deviceModel,
          subDevicesIdList: subDevicesIdList,
          subDevicesNameList: subDevicesNameList,
          deviceTree: deviceTree,
        );
  }
}
